using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VLSPARAM
    {
        public DataRow Convert2LSPARAM(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryLSPARAM(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["LSRMANDANT"] = " ".PadRight(2 ); 
         dwReturn["LSRLIEFNR"] = " ".PadRight(8 ); 
         dwReturn["LSRADRSL"] = " ".PadRight(4 ); 
         dwReturn["LSRBESTA"] = " ".PadRight(1 ); 
         dwReturn["LSRBESL"] = " ".PadRight(8 ); 
         dwReturn["LSRLFSTA"] = " ".PadRight(1 ); 
         dwReturn["LSRLFSL"] = " ".PadRight(8 ); 
         dwReturn["LSRLFWE"] = " ".PadRight(1 ); 
         dwReturn["LSRRESTA"] = " ".PadRight(1 ); 
         dwReturn["LSRRESL"] = " ".PadRight(8 ); 
         dwReturn["LSRLIEFS"] = " ".PadRight(1 ); 
         dwReturn["LSRSTYP01"] = " ".PadRight(3 ); 
         dwReturn["LSRSADR01"] = " ".PadRight(20 ); 
         dwReturn["LSRSKONV01"] = " ".PadRight(4 ); 
         dwReturn["LSRSPFAD01"] = " ".PadRight(40 ); 
         dwReturn["LSRSSOFORT01"] = " ".PadRight(1 ); 
         dwReturn["LSRSTYP02"] = " ".PadRight(3 ); 
         dwReturn["LSRSADR02"] = " ".PadRight(20 ); 
         dwReturn["LSRSKONV02"] = " ".PadRight(4 ); 
         dwReturn["LSRSPFAD02"] = " ".PadRight(40 ); 
         dwReturn["LSRSSOFORT02"] = " ".PadRight(1 ); 
         dwReturn["LSRSTYP03"] = " ".PadRight(3 ); 
         dwReturn["LSRSADR03"] = " ".PadRight(20 ); 
         dwReturn["LSRSKONV03"] = " ".PadRight(4 ); 
         dwReturn["LSRSPFAD03"] = " ".PadRight(40 ); 
         dwReturn["LSRSSOFORT03"] = " ".PadRight(1 ); 
         dwReturn["LSRSTYP04"] = " ".PadRight(3 ); 
         dwReturn["LSRSADR04"] = " ".PadRight(20 ); 
         dwReturn["LSRSKONV04"] = " ".PadRight(4 ); 
         dwReturn["LSRSPFAD04"] = " ".PadRight(40 ); 
         dwReturn["LSRSSOFORT04"] = " ".PadRight(1 ); 
         dwReturn["LSRSTYP05"] = " ".PadRight(3 ); 
         dwReturn["LSRSADR05"] = " ".PadRight(20 ); 
         dwReturn["LSRSKONV05"] = " ".PadRight(4 ); 
         dwReturn["LSRSPFAD05"] = " ".PadRight(40 ); 
         dwReturn["LSRSSOFORT05"] = " ".PadRight(1 ); 
         dwReturn["LSRSTYP06"] = " ".PadRight(3 ); 
         dwReturn["LSRSADR06"] = " ".PadRight(20 ); 
         dwReturn["LSRSKONV06"] = " ".PadRight(4 ); 
         dwReturn["LSRSPFAD06"] = " ".PadRight(40 ); 
         dwReturn["LSRSSOFORT06"] = " ".PadRight(1 ); 
         dwReturn["LSRSTYP07"] = " ".PadRight(3 ); 
         dwReturn["LSRSADR07"] = " ".PadRight(20 ); 
         dwReturn["LSRSKONV07"] = " ".PadRight(4 ); 
         dwReturn["LSRSPFAD07"] = " ".PadRight(40 ); 
         dwReturn["LSRSSOFORT07"] = " ".PadRight(1 ); 
         dwReturn["LSRSTYP08"] = " ".PadRight(3 ); 
         dwReturn["LSRSADR08"] = " ".PadRight(20 ); 
         dwReturn["LSRSKONV08"] = " ".PadRight(4 ); 
         dwReturn["LSRSPFAD08"] = " ".PadRight(40 ); 
         dwReturn["LSRSSOFORT08"] = " ".PadRight(1 ); 
         dwReturn["LSLEER"] = " ".PadRight(83 ); 
         dwReturn["LSRAENZL"] = " ".PadRight(0 ); 
         dwReturn["LSRAENB"] = " ".PadRight(8 ); 
         dwReturn["LSRAEND"] = " ".PadRight(0 ); 
         dwReturn["LSRNEUB"] = " ".PadRight(8 ); 
         dwReturn["LSRNEUD"] = " ".PadRight(0 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapLSPARAM(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveLSPARAM(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryLSPARAM(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapLSPARAM(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertLSPARAM(dwLocal, ITXDBVERSION);
            }
            UpdateLSPARAM(dwLocal);
        }
        public void InsertLSPARAM(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO LSPARAM(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryLSPARAM(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM LSPARAM WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM LSPARAM  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "LSPARAM";
            Return = Result;
            return Return;
        }
        public void DeleteLSPARAM(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM LSPARAM   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateLSPARAM(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE LSPARAM SET "
                    +"LSRMANDANT= :LSRMANDANT,"
                    +"LSRLIEFNR= :LSRLIEFNR,"
                    +"LSRADRSL= :LSRADRSL,"
                    +"LSRBESTA= :LSRBESTA,"
                    +"LSRBESL= :LSRBESL,"
                    +"LSRLFSTA= :LSRLFSTA,"
                    +"LSRLFSL= :LSRLFSL,"
                    +"LSRLFWE= :LSRLFWE,"
                    +"LSRRESTA= :LSRRESTA,"
                    +"LSRRESL= :LSRRESL,"
                    +"LSRLIEFS= :LSRLIEFS,"
                    +"LSRSTYP01= :LSRSTYP01,"
                    +"LSRSADR01= :LSRSADR01,"
                    +"LSRSKONV01= :LSRSKONV01,"
                    +"LSRSPFAD01= :LSRSPFAD01,"
                    +"LSRSSOFORT01= :LSRSSOFORT01,"
                    +"LSRSTYP02= :LSRSTYP02,"
                    +"LSRSADR02= :LSRSADR02,"
                    +"LSRSKONV02= :LSRSKONV02,"
                    +"LSRSPFAD02= :LSRSPFAD02,"
                    +"LSRSSOFORT02= :LSRSSOFORT02,"
                    +"LSRSTYP03= :LSRSTYP03,"
                    +"LSRSADR03= :LSRSADR03,"
                    +"LSRSKONV03= :LSRSKONV03,"
                    +"LSRSPFAD03= :LSRSPFAD03,"
                    +"LSRSSOFORT03= :LSRSSOFORT03,"
                    +"LSRSTYP04= :LSRSTYP04,"
                    +"LSRSADR04= :LSRSADR04,"
                    +"LSRSKONV04= :LSRSKONV04,"
                    +"LSRSPFAD04= :LSRSPFAD04,"
                    +"LSRSSOFORT04= :LSRSSOFORT04,"
                    +"LSRSTYP05= :LSRSTYP05,"
                    +"LSRSADR05= :LSRSADR05,"
                    +"LSRSKONV05= :LSRSKONV05,"
                    +"LSRSPFAD05= :LSRSPFAD05,"
                    +"LSRSSOFORT05= :LSRSSOFORT05,"
                    +"LSRSTYP06= :LSRSTYP06,"
                    +"LSRSADR06= :LSRSADR06,"
                    +"LSRSKONV06= :LSRSKONV06,"
                    +"LSRSPFAD06= :LSRSPFAD06,"
                    +"LSRSSOFORT06= :LSRSSOFORT06,"
                    +"LSRSTYP07= :LSRSTYP07,"
                    +"LSRSADR07= :LSRSADR07,"
                    +"LSRSKONV07= :LSRSKONV07,"
                    +"LSRSPFAD07= :LSRSPFAD07,"
                    +"LSRSSOFORT07= :LSRSSOFORT07,"
                    +"LSRSTYP08= :LSRSTYP08,"
                    +"LSRSADR08= :LSRSADR08,"
                    +"LSRSKONV08= :LSRSKONV08,"
                    +"LSRSPFAD08= :LSRSPFAD08,"
                    +"LSRSSOFORT08= :LSRSSOFORT08,"
                    +"LSLEER= :LSLEER,"
                    +"LSRAENZL= :LSRAENZL,"
                    +"LSRAENB= :LSRAENB,"
                    +"LSRAEND= :LSRAEND,"
                    +"LSRNEUB= :LSRNEUB,"
                    +"LSRNEUD= :LSRNEUD,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("LSRMANDANT", OracleType.NVarChar).Value = dwData["LSRMANDANT"].ToString(); 
          or1.Parameters.Add("LSRLIEFNR", OracleType.NVarChar).Value = dwData["LSRLIEFNR"].ToString(); 
          or1.Parameters.Add("LSRADRSL", OracleType.NVarChar).Value = dwData["LSRADRSL"].ToString(); 
          or1.Parameters.Add("LSRBESTA", OracleType.NVarChar).Value = dwData["LSRBESTA"].ToString(); 
          or1.Parameters.Add("LSRBESL", OracleType.NVarChar).Value = dwData["LSRBESL"].ToString(); 
          or1.Parameters.Add("LSRLFSTA", OracleType.NVarChar).Value = dwData["LSRLFSTA"].ToString(); 
          or1.Parameters.Add("LSRLFSL", OracleType.NVarChar).Value = dwData["LSRLFSL"].ToString(); 
          or1.Parameters.Add("LSRLFWE", OracleType.NVarChar).Value = dwData["LSRLFWE"].ToString(); 
          or1.Parameters.Add("LSRRESTA", OracleType.NVarChar).Value = dwData["LSRRESTA"].ToString(); 
          or1.Parameters.Add("LSRRESL", OracleType.NVarChar).Value = dwData["LSRRESL"].ToString(); 
          or1.Parameters.Add("LSRLIEFS", OracleType.NVarChar).Value = dwData["LSRLIEFS"].ToString(); 
          or1.Parameters.Add("LSRSTYP01", OracleType.NVarChar).Value = dwData["LSRSTYP01"].ToString(); 
          or1.Parameters.Add("LSRSADR01", OracleType.NVarChar).Value = dwData["LSRSADR01"].ToString(); 
          or1.Parameters.Add("LSRSKONV01", OracleType.NVarChar).Value = dwData["LSRSKONV01"].ToString(); 
          or1.Parameters.Add("LSRSPFAD01", OracleType.NVarChar).Value = dwData["LSRSPFAD01"].ToString(); 
          or1.Parameters.Add("LSRSSOFORT01", OracleType.NVarChar).Value = dwData["LSRSSOFORT01"].ToString(); 
          or1.Parameters.Add("LSRSTYP02", OracleType.NVarChar).Value = dwData["LSRSTYP02"].ToString(); 
          or1.Parameters.Add("LSRSADR02", OracleType.NVarChar).Value = dwData["LSRSADR02"].ToString(); 
          or1.Parameters.Add("LSRSKONV02", OracleType.NVarChar).Value = dwData["LSRSKONV02"].ToString(); 
          or1.Parameters.Add("LSRSPFAD02", OracleType.NVarChar).Value = dwData["LSRSPFAD02"].ToString(); 
          or1.Parameters.Add("LSRSSOFORT02", OracleType.NVarChar).Value = dwData["LSRSSOFORT02"].ToString(); 
          or1.Parameters.Add("LSRSTYP03", OracleType.NVarChar).Value = dwData["LSRSTYP03"].ToString(); 
          or1.Parameters.Add("LSRSADR03", OracleType.NVarChar).Value = dwData["LSRSADR03"].ToString(); 
          or1.Parameters.Add("LSRSKONV03", OracleType.NVarChar).Value = dwData["LSRSKONV03"].ToString(); 
          or1.Parameters.Add("LSRSPFAD03", OracleType.NVarChar).Value = dwData["LSRSPFAD03"].ToString(); 
          or1.Parameters.Add("LSRSSOFORT03", OracleType.NVarChar).Value = dwData["LSRSSOFORT03"].ToString(); 
          or1.Parameters.Add("LSRSTYP04", OracleType.NVarChar).Value = dwData["LSRSTYP04"].ToString(); 
          or1.Parameters.Add("LSRSADR04", OracleType.NVarChar).Value = dwData["LSRSADR04"].ToString(); 
          or1.Parameters.Add("LSRSKONV04", OracleType.NVarChar).Value = dwData["LSRSKONV04"].ToString(); 
          or1.Parameters.Add("LSRSPFAD04", OracleType.NVarChar).Value = dwData["LSRSPFAD04"].ToString(); 
          or1.Parameters.Add("LSRSSOFORT04", OracleType.NVarChar).Value = dwData["LSRSSOFORT04"].ToString(); 
          or1.Parameters.Add("LSRSTYP05", OracleType.NVarChar).Value = dwData["LSRSTYP05"].ToString(); 
          or1.Parameters.Add("LSRSADR05", OracleType.NVarChar).Value = dwData["LSRSADR05"].ToString(); 
          or1.Parameters.Add("LSRSKONV05", OracleType.NVarChar).Value = dwData["LSRSKONV05"].ToString(); 
          or1.Parameters.Add("LSRSPFAD05", OracleType.NVarChar).Value = dwData["LSRSPFAD05"].ToString(); 
          or1.Parameters.Add("LSRSSOFORT05", OracleType.NVarChar).Value = dwData["LSRSSOFORT05"].ToString(); 
          or1.Parameters.Add("LSRSTYP06", OracleType.NVarChar).Value = dwData["LSRSTYP06"].ToString(); 
          or1.Parameters.Add("LSRSADR06", OracleType.NVarChar).Value = dwData["LSRSADR06"].ToString(); 
          or1.Parameters.Add("LSRSKONV06", OracleType.NVarChar).Value = dwData["LSRSKONV06"].ToString(); 
          or1.Parameters.Add("LSRSPFAD06", OracleType.NVarChar).Value = dwData["LSRSPFAD06"].ToString(); 
          or1.Parameters.Add("LSRSSOFORT06", OracleType.NVarChar).Value = dwData["LSRSSOFORT06"].ToString(); 
          or1.Parameters.Add("LSRSTYP07", OracleType.NVarChar).Value = dwData["LSRSTYP07"].ToString(); 
          or1.Parameters.Add("LSRSADR07", OracleType.NVarChar).Value = dwData["LSRSADR07"].ToString(); 
          or1.Parameters.Add("LSRSKONV07", OracleType.NVarChar).Value = dwData["LSRSKONV07"].ToString(); 
          or1.Parameters.Add("LSRSPFAD07", OracleType.NVarChar).Value = dwData["LSRSPFAD07"].ToString(); 
          or1.Parameters.Add("LSRSSOFORT07", OracleType.NVarChar).Value = dwData["LSRSSOFORT07"].ToString(); 
          or1.Parameters.Add("LSRSTYP08", OracleType.NVarChar).Value = dwData["LSRSTYP08"].ToString(); 
          or1.Parameters.Add("LSRSADR08", OracleType.NVarChar).Value = dwData["LSRSADR08"].ToString(); 
          or1.Parameters.Add("LSRSKONV08", OracleType.NVarChar).Value = dwData["LSRSKONV08"].ToString(); 
          or1.Parameters.Add("LSRSPFAD08", OracleType.NVarChar).Value = dwData["LSRSPFAD08"].ToString(); 
          or1.Parameters.Add("LSRSSOFORT08", OracleType.NVarChar).Value = dwData["LSRSSOFORT08"].ToString(); 
          or1.Parameters.Add("LSLEER", OracleType.NVarChar).Value = dwData["LSLEER"].ToString(); 
          or1.Parameters.Add("LSRAENZL", OracleType.NVarChar).Value = dwData["LSRAENZL"].ToString(); 
          or1.Parameters.Add("LSRAENB", OracleType.NVarChar).Value = dwData["LSRAENB"].ToString(); 
          or1.Parameters.Add("LSRAEND", OracleType.NVarChar).Value = dwData["LSRAEND"].ToString(); 
          or1.Parameters.Add("LSRNEUB", OracleType.NVarChar).Value = dwData["LSRNEUB"].ToString(); 
          or1.Parameters.Add("LSRNEUD", OracleType.NVarChar).Value = dwData["LSRNEUD"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
